﻿namespace ETestIT.UI.AppControls
{
    using System;
    using System.Web.UI;
    using Domain.Entities;

    public partial class UserAddEdit : UserControl
    {
        public event EventHandler Update;

        public string UserName
        {
            get { return tbName.Text.Trim(); }
            set { tbName.Text = value; }
        }

        public string UserPassword
        {
            get { return tbPassword.Text.Trim(); }
            set { tbPassword.Attributes.Add("value", value); }
        }

        public void SetModel(User user)
        {
            UserName = user.Name;
            UserPassword = user.Password;
        }

        public void UpdateModelFromUserInput(User user)
        {
            user.Name = UserName;
            user.Password = UserPassword;
        }

        public bool IsInputValide()
        {
            return !string.IsNullOrEmpty(UserName);  
        }

        protected void bntUpdate_Clicked(object sender, EventArgs e)
        {
            if (Update != null)
                Update(sender, e);
        }
    }
}